package com.nifostasky.comic.controller;

import com.nifostasky.comic.entitys.SysUser;
import com.nifostasky.comic.query.SysUserQuery;
import com.nifostasky.comic.service.SysUserService;
import com.nifostasky.comic.utils.PageUtils;
import com.nifostasky.comic.vos.JsonResult;
import com.nifostasky.comic.vos.SysUserVO;
import io.swagger.annotations.*;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/user")
@Api(tags = "用户管理", position = 1)
@AllArgsConstructor
public class SysUserController {
    private SysUserService userService;

    @ApiOperation(value = "分页列表",notes = "带参分页查询列表")
    @GetMapping("findListPage")
    @ApiOperationSupport(order = 1)
    public JsonResult findListPage(PageUtils pageUtils, SysUserQuery sysUserQuery){
        return new JsonResult(userService.findListPage(pageUtils, sysUserQuery));
    }

    @ApiOperation("新增/修改")
    @PostMapping("/saveOrUpdate")
    @ApiOperationSupport(order = 2)
    public JsonResult saveOrUpdate(@RequestBody SysUser sysUser){
        return new JsonResult(userService.saveOrUpdateUser(sysUser));
    }

    @ApiOperation("根据主键id获取信息")
    @GetMapping("/getData")
    @ApiResponses(@ApiResponse(code = 200,message = "返回成功",response = SysUser.class))
    @ApiImplicitParams(
            @ApiImplicitParam(name = "id", value = "主键id", dataType = "Int",required = true)
    )
    @ApiOperationSupport(order = 3)
    public JsonResult<SysUser> getData(Long id){
        return new JsonResult(userService.getById(id));
    }
    @ApiOperation("单个或批量删除")
    @GetMapping("/deleteByIds")
    @ApiOperationSupport(order = 4)
    public JsonResult deleteByIds(@ApiParam("主键ids，批量删除时id用英文逗号隔开数据格式:id1,id2,id3,...") String ids){
        return new JsonResult(userService.deleteUserAllById(ids));
    }
    @ApiOperation("用户设置角色")
    @PostMapping("/setRole")
    @ApiOperationSupport(order = 5)
    public JsonResult setRole(@RequestBody SysUserVO sysUserVo){
       Boolean bool = userService.setRole(sysUserVo.getId(),sysUserVo.getRoleIds());
        return new JsonResult(bool);
    }

    @ApiOperation(value = "根据用户id获取角色信息", notes = "根据用户id获取角色信息")
    @GetMapping("/getRoleIdsByUserId")
    @ApiOperationSupport(order = 6)
    public JsonResult getRoleIdsByUserId(@ApiParam(value = "用户Id", required = true) @RequestParam Long id){
        return new JsonResult<>(userService.getRoleIdsByUserId(id));
    }

    @ApiOperation("重置密码")
    @GetMapping("/restPassWordById")
    @ApiOperationSupport(order = 5)
    public JsonResult restPassWordById(@ApiParam("用户id")@RequestParam Long id){
        return new JsonResult(userService.restPassWordById(id));
    }

}
